<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="司机手机号" prop="sjPhone">
        <el-input v-model="dataForm.sjPhone" placeholder="司机手机号"></el-input>
      </el-form-item>
      <el-form-item label="司机姓名" prop="sjName">
        <el-input v-model="dataForm.sjName" placeholder="司机姓名"></el-input>
      </el-form-item>
      <el-form-item label="司机身份证" prop="sjCardid">
        <el-image style="width: 100px; height: 100px" :src="dataForm.sjCardid" :preview-src-list="[dataForm.sjCardid]">
          <div slot="error" class="image-slot">
            <i class="el-icon-picture-outline"></i>
          </div>
        </el-image>
      </el-form-item>
      <el-form-item label="司机驾驶证" prop="sjDrivie">
        <el-image style="width: 100px; height: 100px" :src="dataForm.sjDrivie" :preview-src-list="[dataForm.sjDrivie]">
          <div slot="error" class="image-slot">
            <i class="el-icon-picture-outline"></i>
          </div>
        </el-image>
        <!-- <el-input v-model="dataForm.sjDrivie" placeholder="司机驾驶证"></el-input> -->
      </el-form-item>
      <el-form-item label="司机运营证" prop="sjOperat">
        <el-image style="width: 100px; height: 100px" :src="dataForm.sjOperat" :preview-src-list="[dataForm.sjOperat]">
          <div slot="error" class="image-slot">
            <i class="el-icon-picture-outline"></i>
          </div>
        </el-image>
        <!-- <el-input v-model="dataForm.sjOperat" placeholder="司机运营证"></el-input> -->
      </el-form-item>
      <!-- <el-form-item label="司机余额" prop="sjBalance">
      <el-input v-model="dataForm.sjBalance" placeholder="司机余额"></el-input>
    </el-form-item>
    <el-form-item label="司机限额" prop="sjQuota">
      <el-input v-model="dataForm.sjQuota" placeholder="司机限额"></el-input>
    </el-form-item> -->
      <!-- <el-form-item label="司机状态" prop="sjState">
      <el-input v-model="dataForm.sjState" placeholder="司机状态"></el-input>
    </el-form-item> -->
      <el-form-item label="司机注册时间" prop="sjCreate">
        <el-input v-model="dataForm.sjCreate" placeholder="司机注册时间"></el-input>
      </el-form-item>
      <!-- <el-form-item label="逻辑删除" prop="isDelete">
      <el-input v-model="dataForm.isDelete" placeholder="逻辑删除"></el-input>
    </el-form-item> -->
      <el-form-item label="邀请码" prop="invited">
        <el-input v-model="dataForm.invited" placeholder="邀请码"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">审核通过</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        sjId: 0,
        sjPhone: '',
        sjName: '',
        sjCardid: '',
        sjDrivie: '',
        sjOperat: '',
        sjBalance: '',
        sjQuota: '',
        sjState: '',
        sjCreate: '',
        isDelete: '',
        invited: ''
      },
      dataRule: {
        sjPhone: [
          { required: false, message: '司机手机号不能为空', trigger: 'blur' }
        ],
        sjName: [
          { required: false, message: '司机姓名不能为空', trigger: 'blur' }
        ],
        sjCardid: [
          { required: false, message: '司机身份证不能为空', trigger: 'blur' }
        ],
        sjDrivie: [
          { required: false, message: '司机驾驶证不能为空', trigger: 'blur' }
        ],
        sjOperat: [
          { required: false, message: '司机运营证不能为空', trigger: 'blur' }
        ],
        sjBalance: [
          { required: false, message: '司机余额不能为空', trigger: 'blur' }
        ],
        sjQuota: [
          { required: false, message: '司机限额不能为空', trigger: 'blur' }
        ],
        sjState: [
          { required: false, message: '司机状态不能为空', trigger: 'blur' }
        ],
        sjCreate: [
          { required: false, message: '司机注册时间不能为空', trigger: 'blur' }
        ],
        invited: [
          { required: false, message: '邀请码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.sjId = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.sjId) {
          this.$http({
            url: this.$http.adornUrl(`/driver/ssmsj/info/${this.dataForm.sjId}`),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm.sjPhone = data.ssmSj.sjPhone
              this.dataForm.sjName = data.ssmSj.sjName
              this.dataForm.sjCardid = data.ssmSj.sjCardid
              this.dataForm.sjDrivie = data.ssmSj.sjDrivie
              this.dataForm.sjOperat = data.ssmSj.sjOperat
              this.dataForm.sjBalance = data.ssmSj.sjBalance
              this.dataForm.sjQuota = data.ssmSj.sjQuota
              this.dataForm.sjState = data.ssmSj.sjState
              this.dataForm.sjCreate = data.ssmSj.sjCreate
              this.dataForm.isDelete = data.ssmSj.isDelete
              this.dataForm.invited = data.ssmSj.invited
            }
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/driver/ssmsj/${!this.dataForm.sjId ? 'save' : 'update'}`),
            method: 'post',
            data: this.$http.adornData({
              'sjId': this.dataForm.sjId || undefined,
              'sjPhone': this.dataForm.sjPhone,
              'sjName': this.dataForm.sjName,
              'sjCardid': this.dataForm.sjCardid,
              'sjDrivie': this.dataForm.sjDrivie,
              'sjOperat': this.dataForm.sjOperat,
              'sjBalance': this.dataForm.sjBalance,
              'sjQuota': this.dataForm.sjQuota,
              'sjState': 1,
              'sjCreate': this.dataForm.sjCreate,
              'isDelete': this.dataForm.isDelete,
              'invited': this.dataForm.invited
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })
    }
  }
}
</script>
